package com.tang.crm.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tang.crm.dto.CustomerOrderDto;
import com.tang.crm.entity.CustomerOrder;
import com.tang.crm.mapper.CustomerOrderMapper;
import com.tang.crm.service.CustomerOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class CustomerOrderServiceImpl extends ServiceImpl<CustomerOrderMapper, CustomerOrder> implements CustomerOrderService {

    @Autowired
    private CustomerOrderMapper customerOrderMapper;

    /**
     * 多条件分页查询客户 （返回的数据格式必须满足LayUi中数据表格要求的格式）
     * @param customerOrderDto
     * @return
     */
    @Override
    public Map<String, Object> selectByParams(CustomerOrderDto customerOrderDto) {
        Map<String, Object> map = new HashMap<>();
        IPage<CustomerOrder> iPage = new Page<>(customerOrderDto.getPage(), customerOrderDto.getLimit());
        IPage<Map<String, Object>> mapIPage = customerOrderMapper.selectAllByParams(iPage, customerOrderDto);
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", mapIPage.getTotal());
        map.put("data", mapIPage.getRecords());
        return map;
    }

    /**
     * 通过订单ID查询对应的订单记录
     * @param orderId
     * @return
     */
    @Override
    public Map<String, Object> selectOrderById(Integer orderId) {
        return customerOrderMapper.selectOrderById(orderId);
    }

}
